package com.esun.service.component;

import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author John.xiao
 * @date 2021/10/13 14:53
 */
@Component
public class OperationLogComponent {
	private final Map<Long,RetryEntity> errorLogs = new HashMap<>();

	public void setErrorLogs(Long time,String log){
		RetryEntity retryEntity = RetryEntity.builder().message(log).retryTimes(0).build();
		errorLogs.put(time,retryEntity);
	}

	public Map<Long,RetryEntity> getErrorLogs(){
		return this.errorLogs;
	}

	public String getErrorLog(Long time){
		if (errorLogs.containsKey(time)){
			return errorLogs.get(time).getMessage();
		}
		return "empty log";
	}

	public void clear(){
		errorLogs.clear();
	}

	public void remove(Long time){
		errorLogs.remove(time);
	}
}
